﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Pic
{
    public class PicTagService : IPicTagService
    {
        Domain.Uow.IRepository<Domain.Entity.PicTag> picTagRepository;

        public PicTagService(Domain.Uow.IRepository<Domain.Entity.PicTag> picTag)
        {
            if (picTag == null)
            {
                throw new ArgumentNullException("picTagRepository is null");
            }
            picTagRepository = picTag;
        }

        public Domain.Entity.PicTag Add(Domain.Entity.PicTag add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            picTagRepository.Add(add);
            picTagRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.PicTag delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                picTagRepository.Modify(delete);
                picTagRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.PicTag delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                picTagRepository.Delete(delete);
                picTagRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = picTagRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                picTagRepository.Modify(item);
            }
            try
            {
                picTagRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = picTagRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                picTagRepository.Delete(item);
            }
            try
            {
                picTagRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.PicTag modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                picTagRepository.Modify(modify);
                picTagRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.PicTag Get(int id)
        {
            var data = picTagRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.PicTag> GetList()
        {
            var data = picTagRepository.GetList();
            return data;
        }
    }
}
